import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, App } from 'ionic-angular';
import { BusiserviceProvider } from '../../providers/busiservice/busiservice';
import { UiserviceProvider } from '../../providers/uiservice/uiservice';

/**
 * Generated class for the ZwlistPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-zwlist',
  templateUrl: 'zwlist.html',
})
export class ZwlistPage {
  zwlist = [];
  searchtext: any;
  constructor(public navCtrl: NavController, public navParams: NavParams,
    public appCtrl: App, public busi: BusiserviceProvider, private uiservice: UiserviceProvider) {
    this.getZwList();
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad ZwlistPage');
  }
  private getZwList() {
    this.uiservice.showLoading();
    this.busi.getZwlist().subscribe(
      data => {
        this.uiservice.hideLoading();
        if (data._success) {
          this.zwlist = data.result;
        } else {
          this.uiservice.showAlert(data._message);
        }
      },
      error => {
        this.uiservice.hideLoading();
        this.uiservice.showAlert("Net Error");
      }
    )
  }
  private zwdetail(zw) {
    this.navCtrl.push("ZwdetailPage", { zw: zw })
  }
  private exit() {
    this.appCtrl.getRootNav().setRoot("LoginChoicePage");
  }
  gotosearch() {
    this.navCtrl.push("ZwsearchPage",{callback:this.callback});
  }
  callback = (searchList) => {
    return new Promise((reslove, reject) => {
      this.zwlist = searchList;
      reslove();
    })
  }

}
